<template>
    <el-row>
        <h5>导航栏</h5>
        <el-radio-group v-model="isCollapse" style="margin-bottom: 15px; margin-top: 12px;">

        <el-radio-button :value="true">收缩</el-radio-button>
        <el-radio-button :value="false">展开</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-menu
        active-text-color="#181818"
        background-color="transparent"
        class="el-menu-vertical-demo"
        default-active="2"
        text-color="#fff"
        :collapse="isCollapse"
      @open="handleOpen"
      @close="handleClose"
    >
      <el-sub-menu index="1">
        <template #title>
          <el-icon><location /></el-icon>
          <span>书籍分类</span>
        </template>
          <el-menu-item index="1-1" @click="handleSelect('1-1')">蔬菜类</el-menu-item>
          <el-menu-item index="1-2" @click="handleSelect('1-2')">零食类</el-menu-item>
          <el-menu-item index="1-3" @click="handleSelect('1-3')">玩具类</el-menu-item>
          <el-menu-item index="1-4" @click="handleSelect('1-4')">生活用品类</el-menu-item>
          <el-menu-item index="1-5" @click="handleSelect('1-5')">其它</el-menu-item>
      </el-sub-menu>
      <el-menu-item index="2" @click="handleSelect('2')">
        <el-icon><icon-menu /></el-icon>
        <template #title>库存统计</template>
      </el-menu-item>
      <el-menu-item index="3" @click="handleSelect('3')">
        <el-icon><document /></el-icon>
        <template #title>出售记录</template>
      </el-menu-item>
      <el-menu-item index="4" @click="handleSelect('4')">
        <el-icon><setting /></el-icon>
        <template #title>账号设置</template>
      </el-menu-item>
    </el-menu>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import {
    Document,
    Menu as IconMenu,
    Location,
    Setting,
} from '@element-plus/icons-vue'

const isCollapse = ref(false)
const handleOpen = (key: string, keyPath: string[]) => {
    // console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
    // console.log(key, keyPath)
}

// 获取选中菜单的index
const emit = defineEmits(['select'])
const activeIndex = ref('')
const handleSelect = (index: string) => {
    activeIndex.value = index
    emit('select', activeIndex)
}


</script>

<style lang="scss" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
}
h5 {
    padding: 10px;
    margin-top: 6px;
    color: #d2bfc0;
    font-size: 17px;
}


</style>
